// 在vue-config.js 中加入
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];
const isProduction = process.env.NODE_ENV === 'production';

const path = require('path');

module.exports = {
	productionSourceMap: false, //优化打包体积
	publicPath: './',
	lintOnSave: false,
	publicPath: process.env.NODE_ENV === "production" ? "https://test.tongfun.com/" : "/",
	outputDir: "dist",
	indexPath: "index.html",


	devServer: {
		open: true, //配置自动启动浏览器

		// 配置多个代理
		proxy: {
			"/api": {
				target: "http://192.168.0.8:8099/api", // 本地模拟数据服务器
				changeOrigin: true,
				pathRewrite: {
					"^/api": "" // 去掉接口地址中的api字符串
				}
			}
		}
	},

	pluginOptions: {
		'style-resources-loader': {
			preProcessor: 'less',
			patterns: [
				path.resolve(__dirname, './src/assets/css/global.less')
			]
		}
	},
	configureWebpack: config => {
		// 代码压缩
		// ..................
		// gzip压缩
		const productionGzipExtensions = ['html', 'js', 'css','img']
		config.plugins.push(
			new CompressionWebpackPlugin({
				filename: '[path].gz[query]',
				algorithm: 'gzip',
				test: new RegExp(
					'\\.(' + productionGzipExtensions.join('|') + ')$'
				),
				threshold: 1024, // 只有大小大于该值的资源会被处理 10240
				minRatio: 1, // 只有压缩率小于这个值的资源才会被处理
				deleteOriginalAssets: false // 删除原文件
			})
		)
	}
};
